﻿@model kozvetito.Models.RegisterViewModel
           
<input type="button" value="Regisztráció" class="btn btn-default" id="regOpen" />

<div id="regPanel" title="Regisztráció">
    @using (Html.BeginForm("Register", "User", FormMethod.Post, new { area = "", id = "regForm" }))
    {
        @Html.AntiForgeryToken()

        <div class="form-horizontal">

            <input type="hidden" autofocus />
            <div id="errorReg" class="validation-summary-errors"></div>

            <div class="form-group">
                <div class="col-md-12">
                    @Html.TextBoxFor(model => model.UserName, new { @class = "form-control", @placeholder = HttpUtility.HtmlDecode(Html.DisplayNameFor(m => m.UserName).ToString()) })
                    @Html.ValidationMessageFor(model => model.UserName)
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    @Html.PasswordFor(model => model.Password, new { @class = "form-control", @placeholder = HttpUtility.HtmlDecode(Html.DisplayNameFor(m => m.Password).ToString()) })
                    @Html.ValidationMessageFor(model => model.Password)
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    @Html.PasswordFor(model => model.ConfirmPassword, new { @class = "form-control", @placeholder = HttpUtility.HtmlDecode(Html.DisplayNameFor(m => m.ConfirmPassword).ToString()) })
                    @Html.ValidationMessageFor(model => model.ConfirmPassword)
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-10">
                    @Html.LabelFor(model => model.Ferfi)
                    @Html.RadioButtonFor(model => model.Ferfi, true) Férfi
                    @Html.RadioButtonFor(model => model.Ferfi, false) Nő
                    @Html.ValidationMessageFor(model => model.Ferfi)
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    @Html.TextBoxFor(model => model.Nev, new { @class = "form-control", @placeholder = HttpUtility.HtmlDecode(Html.DisplayNameFor(m => m.Nev).ToString()) })
                    @Html.ValidationMessageFor(model => model.Nev)
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    @Html.TextBoxFor(model => model.EMail, new { @class = "form-control", @placeholder = HttpUtility.HtmlDecode(Html.DisplayNameFor(m => m.EMail).ToString()) })
                    @Html.ValidationMessageFor(model => model.EMail)
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Felhaszn_feltetel)
                    @Html.DisplayNameFor(model => model.Felhaszn_feltetel)
                    @Html.ValidationMessageFor(model => model.Felhaszn_feltetel)
                </div>
            </div>
        </div>
    }
</div>


@Styles.Render("~/Content/jqueryui")
@Styles.Render("~/bundles/msgboxcss")

@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/msgbox")

<script>
    $(function() {
        $("#regPanel").dialog({
            autoOpen: false,
            dialogClass: "no-close",
            modal: true,
            show: {
                effect: "fade",
                duration: 500
            },
            hide: {
                effect: "explode",
                duration: 500
            },
            width: 500,
            buttons: [{
                text: "Regisztráció",
                click: function () {
                    if ($("#Felhaszn_feltetel").is(":checked")) {
                        if ($("#regForm").valid()) {
                            $.msgBox({
                                title: "Regisztráció folyamatban",
                                type: "progress"
                            })
                            $.post("../User/Register",
                            $("#regForm").serialize(),
                            function (data, status, xhr) {
                                if (data.Success) {
                                    window.onload.reload();
                                } else {
                                    $(".msgBox").hide();
                                    $(".msgBoxBackGround").hide();
                                    $("#errorReg").html(data.Errors);
                                    $("#regPanel").effect("shake")
                                }
                            })
                        }
                    } else {
                        $.msgBox({
                            title: "Sikertelen regisztráció!",
                            content: "A regisztrációhoz kötelező elfogadni a felhasználási feltételeket!",
                            type: "error"
                        })
                    }
                }
            },
                {
                    text: "Mégse",
                    click: function () {
                        $(this).dialog("close");
                    }
                }]
        })

        $("#regOpen").on("click", function () {
            $("#regPanel").dialog("open");
        })
    })
</script>